package com.cool.collect.demo;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: xiemiao
 * @CreateTime: 2023-03-16  14:34
 * @Description: TODO
 * @Version: 1.0
 */
public class ConvertUtils {

    public static String convertToSeq(String expression) {
        Pattern compile = Pattern.compile("[A-Z]");
        Matcher matcher = compile.matcher(expression);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
        }
        matcher.appendTail(sb);

        String exp = sb.toString()
                .replace("&&", " and ")
                .replace("||", " or ")
                .replace("==", " = ");
        return "identity('" + exp + "')";
    }

    public static void main(String[] args) {
        String s = "((sCompanyId==CORP001&&sCheckGroupIdinCHK001,CHK002) ||( sRootUnitId=='SRT001'||sCheckGroupIdnot inCHK001,CHK002))";
        String convert = convertToSeq(s);
        System.out.println(convert);
    }
}
